package exception;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * 异常处理机制在IO操作中的应用
 */
public class FinallyDemo2 {
    public static void main(String[] args) {
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream("fos.dat");
            fos.write(2);
            FileInputStream fis = new FileInputStream("fos.dat");
            System.out.println(Integer.toBinaryString(fis.read()));
        } catch (IOException e) {
            System.err.println("出错了！在这里解决！");
        }finally {

            try {
                if (fos!=null){
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }
}
